home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
User's Choice Windows CD
/
User's Choice Windows CD (CMS Software)(1993).iso
/
windows4
/
prndrv.zip
/
MAINWND.C
< prev
next >
Wrap
Text File
|
1992-02-20
|
31KB
|
1,001 lines
//*************************************************************
// File name: mainwnd.c
//
// Description:
//
// WinMain and window procedure routines.
//
// This sample demonstrates the usage of the DeviceCapabilities()
// function that is exported by most printer drivers. The application
// dumps all the possible information that the DeviceCapabilities()
// function supports. This includes basic driver information,
// paper information, bin information, and DEVMODE information.
//
//
// Development Team:
//
// Don Miller
//
//
// Written by Microsoft Product Support Services, Windows Developer Support
// Copyright (c) 1992 Microsoft Corporation. All rights reserved.
//*************************************************************
#include <windows.h>
#include <string.h>
#include <io.h>
#include <drivinit.h>
#include "globals.h"
#include "about.h"
#include "mainwnd.h"
#include "devmode.h"
//*************************************************************
// Function: MainWndProc
//
// Purpose : Message handler for main, overlapped window.
//
// Parms : hWnd == Handle to _this_ window.
// message == Message to process.
// wParam == WORD parameter -- depends on message
// lParam == LONG parameter -- depends on message
//
// Returns : Depends on message.
//
// Comments:
//
//
// History: Date Author Comment
// 1/29/92 Don Miller
//*************************************************************
long FAR PASCAL MainWndProc (HWND hWnd,
unsigned message,
WORD wParam,
LONG lParam)
{
switch (message)
{
case WM_SIZE:
// get size of client window
ixClient = LOWORD(lParam);
iyClient = HIWORD(lParam);
break;
case WM_CREATE:
{
TEXTMETRIC tm;
HDC hdc;
//initialize globals
hDriver = NULL;
nCurrentDevice = 0;
nCurrentInfo = IDM_DRVINFO;
// get fixed font
hdc = GetDC (hWnd) ;
SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT)) ;
GetTextMetrics (hdc, &tm) ;
cxChar = tm.tmAveCharWidth ;
cyChar = tm.tmHeight + tm.tmExternalLeading ;
ReleaseDC (hWnd, hdc) ;
lParam = NULL ;
} // fall through
case WM_WININICHANGE:
{
HMENU hMenu;
// start building device menu list
if (lParam != NULL && lstrcmp ((LPSTR) lParam, "devices") != 0)
return 0 ;
hMenu = GetSubMenu (GetMenu (hWnd), 0) ;
while (GetMenuItemCount (hMenu) > 1)
DeleteMenu (hMenu, 1, MF_BYPOSITION) ;
GetProfileString ("devices", NULL, "", szAllDevices,
sizeof szAllDevices) ;
// add devices to File menu
n = IDM_TOP;
szPtr = szAllDevices ;
while (*szPtr)
{
AppendMenu (hMenu, n % 16 ? 0 : MF_MENUBARBREAK, n, szPtr);
n++ ;
szPtr += strlen (szPtr) + 1 ;
}
// add Exit and About menu choices
AppendMenu (hMenu, MF_SEPARATOR, 0, NULL) ;
AppendMenu (hMenu, MF_STRING, IDM_EXIT, (LPSTR)"E&xit") ;
AppendMenu (hMenu, MF_SEPARATOR, 0, NULL) ;
AppendMenu (hMenu, MF_STRING, IDM_ABOUT, (LPSTR)"&About") ;
}
break;
// Dispatch WM_COMMAND messages to our command handler, DoCommands().
case WM_COMMAND:
return DoCommands (hWnd, message, wParam, lParam);
case WM_PAINT:
{
PAINTSTRUCT ps;
int iOldMode;
BeginPaint(hWnd, &ps);
// set mode to transparent and select fixed font
iOldMode = SetBkMode(ps.hdc, TRANSPARENT);
SelectObject (ps.hdc, GetStockObject (SYSTEM_FIXED_FONT)) ;
// display information for current choice
if (hDriver)
{
switch (nCurrentInfo)
{
// display driver info
case IDM_DRVINFO:
DumpDriverInfo(ps.hdc);
break;
// display paper size info
case IDM_PAPERSIZES:
DumpPaperInfo(ps.hdc);
break;
// display bin info
case IDM_BINS:
DumpBinInfo(ps.hdc);
break;
// display DEVMODE info
case IDMDEVMODE:
DumpDevmodeInfo(hWnd, ps.hdc);
break;
default:
break;
}
}
else // No printer driver has been selected
TextOut(ps.hdc, 10, 10, (LPSTR)"No driver selected!", 19);
SetBkMode(ps.hdc, iOldMode);
EndPaint(hWnd, &ps);
}
break;
// On WM_DESTROY, terminate this app by posting a WM_QUIT message.
case WM_DESTROY:
PostQuitMessage(0);
break;
// We didn't handle, pass to DefWindowProc.
default:
return DefWindowProc (hWnd, message, wParam, lParam);
}
return (NULL);
}
//************************************************************
// Function: DoCommands
//
// Purpose : Called by MainWndProc() to handle all WM_COMMAND type
// messages.
//
// Parms : hWnd == Handle to _this_ window.
// message == Message to process.
// wParam == WORD parameter -- depends on message
// lParam == LONG parameter -- depends on message
//
// Returns : Depends on message.
//
// Comments:
//
//
// History: Date Author Comment
// 1/29/92 Don Miller
//*************************************************************
long DoCommands (HWND hWnd,
unsigned message,
WORD wParam,
LONG lParam)
{
// a device was selected
if (wParam < IDM_EXIT)
{
HMENU hMenu;
hMenu = GetMenu(hWnd);
// check new printer name in File menu
CheckMenuItem(hMenu, nCurrentDevice, MF_UNCHECKED);
nCurrentDevice = wParam;
CheckMenuItem(hMenu, nCurrentDevice, MF_CHECKED);
// get printer driver name
GetMenuString(hMenu, nCurrentDevice, (LPSTR)szDevice, sizeof(szDevice),
MF_BYCOMMAND);
GetProfileString("devices", (LPSTR)szDevice, "", (LPSTR)szDriver,
sizeof(szDriver));
szOutput = strtok(szDriver, ",");
szOutput = strtok(NULL, ",");
lstrcpy((LPSTR)szDriverFile, (LPSTR)szDriver);
lstrcat((LPSTR)szDriverFile, (LPSTR)".DRV");
// check if driver already loaded
if (hDriver >=32)
{
FreeLibrary(hDriver);
hDriver = NULL;
}
// load printer driver
if ((hDriver = LoadLibrary((LPSTR)szDriverFile)) < 32)
return 0;
// set window caption to printer device name
SetWindowText(hWnd, (LPSTR)szDevice);
CheckMenuItem(hMenu, nCurrentInfo, MF_CHECKED);
InvalidateRect(hWnd, NULL, TRUE);
}
else
{
switch (wParam)
{
// check respective menu choice
case IDM_DRVINFO:
case IDM_PAPERSIZES:
case IDM_BINS:
case IDMDEVMODE:
{
HMENU hMenu;
hMenu = GetMenu(hWnd);
// check appropriate choice
CheckMenuItem(hMenu, nCurrentInfo, MF_UNCHECKED);
nCurrentInfo = wParam;
CheckMenuItem(hMenu, nCurrentInfo, MF_CHECKED);
// force a repaint
InvalidateRect(hWnd, NULL, TRUE);
}
break;
// Put up the About box.
case IDM_ABOUT:
{
FARPROC lpDlgProc;
lpDlgProc = MakeProcInstance (AboutDlg, ghInst);
DialogBox (ghInst, // current instance
AboutBoxName, // resource to use
hWnd, // parent handle
lpDlgProc); // About() instance address
FreeProcInstance (lpDlgProc);
break;
}
// User picked File.Exit, terminate this app.
case IDM_EXIT:
// check if driver already loaded
if (hDriver >=32)
{
FreeLibrary(hDriver);
hDriver = NULL;
}
DestroyWindow (hWnd);
break;
default:
return DefWindowProc (hWnd, message, wParam, lParam);
} // end switch
} // end of if
return NULL;
}
//*************************************************************
//
// DumpDriverInfo
//
// Purpose: This function retrieves driver information (file name,
// file date, file size) from the driver and from other
// runtime functions.
//
//
//
// Parameters:
// HDC hDC
//
//
// Return: (BOOL)
//
//
// Comments:
//
//
// History: Date Author Comment
// 1/29/92 Don Miller
//*************************************************************
BOOL DumpDriverInfo(HDC hDC)
{
LPFNDEVCAPS lpfnDeviceCaps;
DWORD dwBufSize = 0;
BOOL bResult = 1;
OFSTRUCT of;
char szBuffer[16];
int i, ixPos, iyPos, iyOrg, ihDRVFile;
unsigned int uiTime, uiDate;
// set column positions
ixPos = cxChar;
iyPos = 0;
// display header text centered
DisplayTextHeader(hDC, ixClient/2, iyPos, (LPSTR)"Driver Info");
// set column positions
iyOrg = 2*cyChar;
iyPos = iyOrg;
// display text
for (i=0; i < 4; i++)
{
TextOut(hDC, ixPos, iyPos, (LPSTR)szDrvInfo[i], lstrlen((LPSTR)szDrvInfo[i]));
iyPos+=iyOrg;
}
// get longest string extent and set x position
ixPos = LOWORD(GetTextExtent(hDC, (LPSTR)"Driver Version:", 15)) + 2*cxChar;
iyPos = iyOrg;
// display printer driver name
TextOut(hDC, ixPos, iyPos, (LPSTR)szDriverFile, lstrlen((LPSTR)szDriverFile));
// open the printer driver file
ihDRVFile = OpenFile((LPSTR)szDriverFile, &of, OF_READ);
// get driver size
wsprintf((LPSTR)szBuffer, "%ld bytes", filelength(ihDRVFile));
TextOut(hDC, ixPos, iyPos+=iyOrg, (LPSTR)szBuffer, lstrlen((LPSTR)szBuffer));
//get driver date
GetFileDateTime(ihDRVFile, &uiTime, &uiDate);
// display date
wsprintf((LPSTR)szBuffer, "%d/%d/%d", (uiDate<<7)>>12, (uiDate<<11)>>11, (uiDate>>9)+80);
TextOut(hDC, ixPos, iyPos+=iyOrg, (LPSTR)szBuffer, lstrlen((LPSTR)szBuffer));
// close the file
_lclose(ihDRVFile);
// check if bad driver
if (IsBadDRV((LPSTR)szDriver))
{
TextOut(hDC, ixPos, iyPos+=iyOrg, (LPSTR)"Driver is considered too buggy concerning DeviceCapabilities!", 61);
return FALSE;
}
// get address of DeviceCapabilities function
lpfnDeviceCaps = (LPFNDEVCAPS) GetProcAddress (hDriver, "DeviceCapabilities");
if (lpfnDeviceCaps)
{
// get driver version
dwBufSize = lpfnDeviceCaps ((LPSTR)szDevice, (LPSTR)szOutput, (WORD)DC_DRIVER,
(LPSTR)NULL, (LPDEVMODE)NULL);
// display driver version
wsprintf((LPSTR)szBuffer, "%lx", dwBufSize);
TextOut(hDC, ixPos, iyPos+=iyOrg, (LPSTR)szBuffer, lstrlen((LPSTR)szBuffer));
}
else
TextOut(hDC, ixPos, iyPos+=iyOrg, (LPSTR)"DeviceCapabilities is not supported by driver!", 46);
return (bResult);
} //*** DumpDriverInfo
//*************************************************************
//
// DumpPaperInfo
//
// Purpose: This function retrieves driver information (paper sizes,
// paper extents) from the driver.
//
//
// Parameters:
// HDC hDC
//
//
// Return: (BOOL)
//
//
// Comments:
//
//
// History: Date Author Comment
// 1/29/92 Don Miller
//*************************************************************
BOOL DumpPaperInfo(HDC hDC)
{
LPFNDEVCAPS lpfnDeviceCaps;
DWORD dwBufSize1 = 0, dwBufSize2 = 0;
BOOL bResult = 1;
WORD FAR *pawPaperList;
HANDLE hPaperList, hPaperDims;
POINT FAR *paptPaperList;
char szBuffer[64];
int i, ixPos, iyPos, iyOrg;
// check if bad driver
if (IsBadDRV((LPSTR)szDriver))
{
TextOut(hDC, 10, 10, (LPSTR)"Driver is considered too buggy concerning DeviceCapabilities!", 61);
return FALSE;
}
// get address of DeviceCapabilities function
lpfnDeviceCaps = (LPFNDEVCAPS) GetProcAddress (hDriver, "DeviceCapabilities");
if (lpfnDeviceCaps)
{
// set column position
ixPos = cxChar;
iyPos = 0;
// display heading
DisplayTextHeader(hDC, ixClient/2, iyPos, (LPSTR)"Paper Sizes Info");
// set column position
iyOrg = cyChar;
iyPos = iyOrg;
// get number of paper sizes
dwBufSize1 = lpfnDeviceCaps ((LPSTR)szDevice, (LPSTR)szOutput, (WORD)DC_PAPERS,
(LPSTR)NULL, (LPDEVMODE)NULL);
// get paper dimensions
dwBufSize2 = lpfnDeviceCaps ((LPSTR)szDevice, (LPSTR)szOutput, (WORD)DC_PAPERSIZE,
(LPSTR)NULL, (LPDEVMODE)NULL);
// allocate space for paper sizes
hPaperList = GlobalAlloc(GMEM_MOVEABLE, dwBufSize1*sizeof(WORD));
pawPaperList = (WORD FAR *) GlobalLock(hPaperList);
// allocate space for paper dimensions
hPaperDims = GlobalAlloc(GMEM_MOVEABLE, dwBufSize2*sizeof(POINT));
paptPaperList = (POINT FAR *) GlobalLock(hPaperDims);
// fill buffer with paper list
lpfnDeviceCaps ((LPSTR)szDevice, (LPSTR)szOutput, (WORD)DC_PAPERS,
(LPSTR)pawPaperList, (LPDEVMODE)NULL);
// fill buffer with paper dimensions
lpfnDeviceCaps ((LPSTR)szDevice, (LPSTR)szOutput, (WORD)DC_PAPERSIZE,
(LPSTR)paptPaperList, (LPDEVMODE)NULL);
TextOut(hDC, ixPos, iyPos+=iyOrg, (LPSTR)"Supported Paper Sizes:", 22);
ixPos = LOWORD(GetTextExtent(hDC, (LPSTR)"Supported Paper Sizes: ", 24));
// display results
if (dwBufSize1 < MAX_AMOUNT)
{
for (i=0; i < (int)dwBufSize1; i++)
{
if ((pawPaperList[i] < MAX_PAPERS) && (pawPaperList[i] > 0))
wsprintf((LPSTR)szBuffer, "%u (%d,%d) %s ", pawPaperList[i],
paptPaperList[i].x, paptPaperList[i].y, (LPSTR)szPaperList[pawPaperList[i]]);
else
wsprintf((LPSTR)szBuffer, "%u (%d,%d) %s ", pawPaperList[i],
paptPaperList[i].x, paptPaperList[i].y, (LPSTR)szPaperList[0]);
TextOut(hDC, ixPos, iyPos, (LPSTR)szBuffer, lstrlen((LPSTR)szBuffer));
iyPos += cyChar;
}
}
else
TextOut(hDC, ixPos, iyPos, (LPSTR)"Driver gave bad info!", 21);
// set column position
ixPos = cxChar;
TextOut(hDC, ixPos, iyPos+=iyOrg, (LPSTR)"Paper Extents:", 14);
ixPos = LOWORD(GetTextExtent(hDC, (LPSTR)"Supported Paper Sizes: ", 24));
// get min paper extent
dwBufSize1 = lpfnDeviceCaps ((LPSTR)szDevice, (LPSTR)szOutput, (WORD)DC_MINEXTENT,
(LPSTR)NULL, (LPDEVMODE)NULL);
// display minimum paper extent
wsprintf((LPSTR)szBuffer, "Min X = %d Min Y = %d", LOWORD(dwBufSize1),
HIWORD(dwBufSize1));
TextOut(hDC, ixPos, iyPos, (LPSTR)szBuffer, lstrlen((LPSTR)szBuffer));
// get max paper extent
dwBufSize1 = lpfnDeviceCaps ((LPSTR)szDevice, (LPSTR)szOutput, (WORD)DC_MAXEXTENT,
(LPSTR)NULL, (LPDEVMODE)NULL);
// display maximum paper extent
wsprintf((LPSTR)szBuffer, "Max X = %d Max Y = %d", LOWORD(dwBufSize1),
HIWORD(dwBufSize1));
TextOut(hDC, ixPos, iyPos+=cyChar, (LPSTR)szBuffer, lstrlen((LPSTR)szBuffer));
// clean up
GlobalUnlock(hPaperList);
GlobalUnlock(hPaperDims);
GlobalFree(hPaperList);
GlobalFree(hPaperDims);
}
else
TextOut(hDC, 10, 10, (LPSTR)"DeviceCapabilities is not supported by driver!", 46);
return (bResult);
} //*** DumpPaperInfo
//*************************************************************
//
// DumpBinInfo
//
// Purpose: This function retrieves driver information (bin
// numbers, bin names) from the driver.
//
//
// Parameters:
// HDC hDC
//
//
// Return: (BOOL)
//
//
// Comments:
//
//
// History: Date Author Comment
// 1/29/92 Don Miller
//*************************************************************
BOOL DumpBinInfo(HDC hDC)
{
LPFNDEVCAPS lpfnDeviceCaps;
DWORD dwBufSize = 0, dwMemSize;
BOOL bResult = 1;
char szBuffer[64];
int i, ixPos, iyPos, iyOrg;
WORD FAR *pawBinList;
HANDLE hBinList;
LPSTR lpstrBinNames;
short FAR *sBinNameNums;
LPSTR lpstrBinNameList;
// check if bad driver
if (IsBadDRV((LPSTR)szDriver))
{
TextOut(hDC, 10, 10, (LPSTR)"Driver is considered too buggy concerning DeviceCapabilities!", 61);
return FALSE;
}
// get address of DeviceCapabilities function
lpfnDeviceCaps = (LPFNDEVCAPS) GetProcAddress (hDriver, "DeviceCapabilities");
if (lpfnDeviceCaps)
{
ixPos = cxChar;
iyPos = 0;
// display header text centered
DisplayTextHeader(hDC, ixClient/2, iyPos, (LPSTR)"Bin Info");
// set column position
iyOrg = cyChar;
iyPos = iyOrg;
// get number of bins
dwBufSize = lpfnDeviceCaps ((LPSTR)szDevice, (LPSTR)szOutput, (WORD)DC_BINS,
(LPSTR)NULL, (LPDEVMODE)NULL);
hBinList = GlobalAlloc(GMEM_MOVEABLE, dwBufSize*sizeof(WORD));
pawBinList = (WORD FAR *) GlobalLock(hBinList);
// fill buffer with bin list
lpfnDeviceCaps ((LPSTR)szDevice, (LPSTR)szOutput, (WORD)DC_BINS,
(LPSTR)pawBinList, (LPDEVMODE)NULL);
TextOut(hDC, ixPos, iyPos+=iyOrg, (LPSTR)"Supported Bin Types:", 20);
ixPos = LOWORD(GetTextExtent(hDC, (LPSTR)"Supported Bin Types: ", 22));
// display bin info
// protects from bad drivers
if ((dwBufSize > 0) && (dwBufSize < MAX_AMOUNT))
{
for (i=0; i < (int)dwBufSize; i++)
{
if (pawBinList[i] < MAX_AMOUNT) // default bins
{
if (pawBinList[i] < MAX_BINS)
wsprintf((LPSTR)szBuffer, "%u %s ", pawBinList[i], (LPSTR)szBinList[pawBinList[i]]);
else
wsprintf((LPSTR)szBuffer, "%u %s ", pawBinList[i], (LPSTR)szBinList[0]);
}
else // device specific bins
wsprintf((LPSTR)szBuffer, "%u %s ", pawBinList[i], (LPSTR)szBinList[15]);
TextOut(hDC, ixPos, iyPos, (LPSTR)szBuffer, lstrlen((LPSTR)szBuffer));
iyPos += cyChar;
}
}
else if (dwBufSize == 0) // no bins
TextOut(hDC, ixPos, iyPos, (LPSTR)"None", 4);
else
{
TextOut(hDC, ixPos, iyPos, (LPSTR)"Driver gave bad info!", 21);
iyPos += cyChar;
}
// clean up
GlobalUnlock(hBinList);
GlobalFree(hBinList);
// get number of named bins
dwBufSize = lpfnDeviceCaps ((LPSTR)szDevice, (LPSTR)szOutput, (WORD)DC_BINNAMES,
(LPSTR)NULL, (LPDEVMODE)NULL);
if ((dwBufSize > 0) && (dwBufSize < MAX_AMOUNT))
{
// get buffer size
dwMemSize = dwBufSize * (sizeof(short) + (CCHBINNAME*sizeof(char)));
// allocate space for bin names
hBinList = GlobalAlloc(GMEM_MOVEABLE, dwMemSize);
lpstrBinNames = GlobalLock(hBinList);
// fill buffer with bin names
lpfnDeviceCaps ((LPSTR)szDevice, (LPSTR)szOutput, (WORD)DC_BINNAMES,
(LPSTR)lpstrBinNames, (LPDEVMODE)NULL);
// display field identifier
ixPos = cxChar;
iyPos += cyChar;;
TextOut(hDC, ixPos, iyPos, (LPSTR)"Named bins:", 11);
ixPos = LOWORD(GetTextExtent(hDC, (LPSTR)"Supported Bin Types: ", 22));
// display bin identifier number and bin name
for (i=0; i < (int)dwBufSize; i++)
{
sBinNameNums = (short FAR *)(lpstrBinNames + (dwBufSize*CCHBINNAME));
lpstrBinNameList = lpstrBinNames;
wsprintf((LPSTR)szBuffer, "%d %s", sBinNameNums[i],
(LPSTR)lpstrBinNameList + (CCHBINNAME*i));
TextOut(hDC, ixPos, iyPos, (LPSTR)szBuffer, lstrlen((LPSTR)szBuffer));
iyPos += cyChar;;
}
// clean up
GlobalUnlock(hBinList);
GlobalFree(hBinList);
}
}
else
TextOut(hDC, 10, 10, (LPSTR)"DeviceCapabilities is not supported by driver!", 46);
return (bResult);
} //*** DumpBinInfo
//*************************************************************
//
// DumpDevmodeInfo
//
// Purpose: This function dumps all the device-independent
// information of the DEVMODE structure.
//
//
//
// Parameters:
// HWND hWnd
// HDC hDC
//
//
// Return: (BOOL)
//
//
// Comments:
//
//
// History: Date Author Comment
// 1/29/92 Don Miller
//*************************************************************
BOOL DumpDevmodeInfo(HWND hWnd, HDC hDC)
{
LPFNDEVMODE lpfnDeviceMode;
DWORD dwBufSize = 0;
BOOL bResult;
char szBuffer[64];
int i, ixPos, ixRightPos, iyPos, iyOrg;
HANDLE hDM;
LPDEVMODE lpDM;
// get address of ExtDeviceMode function
lpfnDeviceMode = (LPFNDEVMODE) GetProcAddress (hDriver, "ExtDeviceMode");
if (lpfnDeviceMode)
{
// get DEVMODE stuff from driver
dwBufSize = lpfnDeviceMode ((HWND)hWnd, (HANDLE)hDriver,
(LPDEVMODE)NULL, (LPSTR)szDevice,
(LPSTR)szOutput, (LPDEVMODE)NULL,
(LPSTR)NULL, (WORD)0);
// alloc space for devmode stuff
hDM = GlobalAlloc(GMEM_MOVEABLE, dwBufSize);
lpDM = (LPDEVMODE)GlobalLock(hDM);
// fill DEVMODE buffer
dwBufSize = lpfnDeviceMode ((HWND)hWnd, (HANDLE)hDriver,
(LPDEVMODE)lpDM, (LPSTR)szDevice,
(LPSTR)szOutput, (LPDEVMODE)NULL,
(LPSTR)NULL, (WORD)DM_COPY);
// set column position
ixPos = cxChar;
iyPos = 0;
// display header text centered
DisplayTextHeader(hDC, ixClient/2, iyPos, (LPSTR)"DEVMODE Info");
iyPos = iyOrg = 2*cyChar;
ixRightPos = LOWORD(GetTextExtent(hDC, (LPSTR)"dmDefaultSource:", 16)) + 2*cxChar;
// display devmode fields
for (i=0; i < MAX_DEVMODE; i++)
{
TextOut(hDC, ixPos, iyPos, (LPSTR)szDevModeList[i], lstrlen((LPSTR)szDevModeList[i]));
switch (i)
{
case 0:
//get DEVMODE's first field
wsprintf((LPSTR)szBuffer, "%s", (LPSTR)lpDM->dmDeviceName );
break;
case 1:
//get DEVMODE's second field
wsprintf((LPSTR)szBuffer, "%xh", (WORD)lpDM->dmSpecVersion);
break;
case 2:
//get DEVMODE's third field
wsprintf((LPSTR)szBuffer, "%xh", (WORD)lpDM->dmDriverVersion);
break;
case 3:
//get DEVMODE's fourth field
wsprintf((LPSTR)szBuffer, "%d bytes", (WORD)lpDM->dmSize);
break;
case 4:
//get DEVMODE's fifth field
wsprintf((LPSTR)szBuffer, "%d bytes", (WORD)lpDM->dmDriverExtra);
break;
case 5:
//get DEVMODE's sixth field
wsprintf((LPSTR)szBuffer, "%lu (bitfield)", (DWORD)lpDM->dmFields);
break;
case 6:
//get DEVMODE's seventh field
if (lpDM->dmOrientation == 2)
wsprintf((LPSTR)szBuffer, "%d DMORIENT_LANDSCAPE", (short)lpDM->dmOrientation);
else
wsprintf((LPSTR)szBuffer, "%d DMORIENT_PORTRAIT", (short)lpDM->dmOrientation);
break;
case 7:
//get DEVMODE's eighth field
wsprintf((LPSTR)szBuffer, "%d %s", (short)lpDM->dmPaperSize,
(LPSTR)szPaperList[lpDM->dmPaperSize]);
break;
case 8:
//get DEVMODE's ninth field
wsprintf((LPSTR)szBuffer, "%d (tenths of a millimeter)", (short)lpDM->dmPaperLength);
break;
case 9:
//get DEVMODE's tenth field
wsprintf((LPSTR)szBuffer, "%d (tenths of a millimeter)", (short)lpDM->dmPaperWidth);
break;
case 10:
//get DEVMODE's eleventh field
wsprintf((LPSTR)szBuffer, "%d", (short)lpDM->dmScale);
break;
case 11:
//get DEVMODE's twelveth field
wsprintf((LPSTR)szBuffer, "%d", (short)lpDM->dmCopies);
break;
case 12:
//get DEVMODE's thirteenth field
if ((lpDM->dmDefaultSource >= 0) && (lpDM->dmDefaultSource < MAX_PAPERS))
wsprintf((LPSTR)szBuffer, "%d %s", (short)lpDM->dmDefaultSource,
(LPSTR)szBinList[lpDM->dmDefaultSource]);
else if (lpDM->dmDefaultSource >= MAX_PAPERS)
wsprintf((LPSTR)szBuffer, "%d %s", (short)lpDM->dmDefaultSource,
(LPSTR)szPaperList[0]);
else
wsprintf((LPSTR)szBuffer, "%d %s", (short)lpDM->dmDefaultSource,
(LPSTR)szBinList[15]);
break;
case 13:
//get DEVMODE's fourteenth field
if (lpDM->dmPrintQuality < 0)
wsprintf((LPSTR)szBuffer, "%d %s", (short)lpDM->dmPrintQuality,
(LPSTR)szPQualityList[-lpDM->dmPrintQuality]);
else if (lpDM->dmPrintQuality >= 0)
wsprintf((LPSTR)szBuffer, "%d %s", (short)lpDM->dmPrintQuality,
(LPSTR)szPQualityList[0]);
break;
case 14:
// get DEVMODE's fifteenth field
if (lpDM->dmColor == DMCOLOR_MONOCHROME)
wsprintf((LPSTR)szBuffer, "%d DMCOLOR_MONOCHROME", (short)lpDM->dmColor);
else if (lpDM->dmColor == DMCOLOR_COLOR)
wsprintf((LPSTR)szBuffer, "%d DMCOLOR_COLOR", (short)lpDM->dmColor);
else
wsprintf((LPSTR)szBuffer, "%d UNKNOWN", (short)lpDM->dmColor);
break;
case 15:
// get DEVMODE's sixteenth field
switch (lpDM->dmDuplex)
{
case DMDUP_SIMPLEX:
wsprintf((LPSTR)szBuffer, "%d DMDUP_SIMPLEX", (short)lpDM->dmDuplex);
break;
case DMDUP_VERTICAL:
wsprintf((LPSTR)szBuffer, "%d DMDUP_VERTICAL", (short)lpDM->dmDuplex);
break;
case DMDUP_HORIZONTAL:
wsprintf((LPSTR)szBuffer, "%d DMDUP_HORIZONTAL", (short)lpDM->dmDuplex);
break;
default:
wsprintf((LPSTR)szBuffer, "%d UNKNOWN", (short)lpDM->dmDuplex);
break;
}
break;
default:
break;
}
TextOut(hDC, ixRightPos, iyPos, (LPSTR)szBuffer, lstrlen((LPSTR)szBuffer));
iyPos += cyChar;
}
GlobalUnlock(hDM);
GlobalFree(hDM);
}
else
TextOut(hDC, 10, 10, (LPSTR)"ExtDeviceMode is not supported by driver!", 41);
return (bResult);
} //*** DumpDevmodeInfo
//*************************************************************
//
// DisplayTextHeader
//
// Purpose: Displays header text centered
//
//
//
// Parameters:
// HDC hDC
// int ixPos
// int iyPos
// LPSTR lpstrHText
//
//
// Return: (void)
//
//
// Comments:
//
//
// History: Date Author Comment
// 1/29/92 Don Miller
//*************************************************************
void DisplayTextHeader(HDC hDC, int ixPos, int iyPos, LPSTR lpstrHText)
{
WORD wOldFlags;
// display header text centered
wOldFlags = SetTextAlign(hDC, TA_CENTER);
TextOut(hDC, ixPos, iyPos, lpstrHText, lstrlen(lpstrHText));
SetTextAlign(hDC, wOldFlags);
} //*** DisplayTextHeader
//*************************************************************
//
// IsBadDRV
//
// Purpose: Checks list of known buggy drivers in DEVMODE.H
//
//
//
// Parameters:
// LPSTR lpstrDRVName
//
//
// Return: (BOOL)
//
//
// Comments:
//
//
// History: Date Author Comment
// 1/29/92 Don Miller
//*************************************************************
BOOL IsBadDRV(LPSTR lpstrDRVName)
{
int i = 0;
BOOL bBadDRV = FALSE;
// checks to see if current printer choice is in list of bad
// drivers list in DEVMODE.H
while ((i < 6) && (!bBadDRV))
{
if (!lstrcmp((LPSTR)szBadDrvs[i], lpstrDRVName))
bBadDRV = TRUE;
i++;
}
return bBadDRV;
} //*** IsBadDRV
/*** EOF: mainwnd.c ***/